{template modoer_header}
<div id="body">
<div class="myhead"></div>
<div class="mymiddle">
    <div class="myleft">
        <!--{template 'menu','member','member'}-->
    </div>
    <div class="myright">
        <div class="myright_top"></div>
        <div class="myright_middle">
            <h3>上传图片</h3>
            <div class="mainrail">
            <!--{if !$sid}-->
                <table width="100%" cellspacing="0" cellpadding="0" class="maintable">
                    <tr>
                        <td width="150" align="right">搜索主题(输入关键字)：</td>
                        <td width="*">
                            <div id="subject_search"></div>
                            <script type="text/javascript">
                                $('#subject_search').item_subject_search({
                                    input_class:'t_input',
                                    btn_class:'btn2',
                                    city_id:$_CITY['aid'],
                                    result_css:'item_search_result',
                                    hide_keyword:true,
                                    myreviewed:true,
                                    myfavorite:true,
                                    location:"{url item/member/ac/$ac/sid/_SID_}"
                                });
                            </script>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><div id="search_result" style="display:none;"></div></td>
                    </tr>
                </table>
            <!--{elseif $_GET['op'] == 'multi'}-->
                <table width="100%" cellspacing="0" cellpadding="0" class="maintable">
                    <!--{eval 
                        $_G['loader']->helper('form','item');
                        $album_option = form_item_alubm($_GET['sid'],$albumid);
                    }-->
                    <tr>
                        <td width="80">上传对象：</td>
                        <td width="*"><a href="{url item/detail/id/$subject[sid]}" target="_blank">$subject[name]&nbsp;$subject[subname]</a>
                        </td>
                    </tr>
                    <tr>
                        <td>所属相册：</td>
                        <td>
                            <select id="albumid">{print $album_option}</select>
                            <button type="button" onclick="item_create_album($sid);">新建相册</button>
                        </td>
                    </tr>
                    <tr>
                        <td>选择图片：</td>
                        <td>
                            <input type="file" name="file_upload" id="file_upload" />
                            <button type="button" onclick="startUpload();" style="position:absolute;margin-top:-33px;margin-left:105px;">开始上传</button>
                        </td>
                    </tr>
                </table>
                <link rel="stylesheet" type="text/css" href="{URLROOT}/static/images/uploadify.css" />
                <script type="text/javascript" src="{URLROOT}/static/javascript/jquery.uploadify.min.js"></script>
                <div id="some_file_queue"></div>
                <script type="text/javascript">
                    <!--{eval 
                        $uploader = str_replace('&amp;','&', url("item/member/ac/$ac/op/post_multi/in_ajax/1",'',true,true));
                        $uphash = $_C['hash'];
                    }-->
                    $(function() {
                        $('#file_upload').uploadify({
                            'fileObjName'   : 'picture',
                            'swf'           : '{URLROOT}/static/images/uploadify/uploadify.swf',
                            'uploader'      : '$uploader',
                            'queueID'       : 'some_file_queue',
                            'fileTypeDesc'  : 'Image Files',
                            'fileTypeExts'  : '*.gif; *.jpg; *.jpeg; *.png',
                            'buttonClass'   : 'select_btn',
                            'buttonText'    : '选择上传图片',
                            'auto'          : false,
                            'width'         : 80,
                            'height'        : 22,
                            'multi'         : true,
                            'uploadLimit'   : 20,
                            'removeCompleted': false,
                            'fileSizeLimit' : '{print (int)$_CFG[picture_upload_size]}KB',
                            'onUploadStart'     : onUploadStart,
                            'onQueueComplete'   : onQueueComplete,
                            'onUploadError'     : onUploadError,
                            'onUploadSuccess'   : onUploadSuccess,
                            'overrideEvents'    : ['onUploadSuccess']
                        });
                    });
                    var picids = '';
                    function startUpload() {
                        var albumid = $('#albumid').val();
                        if(!is_numeric(albumid)) {
                            alert('未选择上传图片的所属相册。');
                            return false;
                        }
                        var formData = {
                            'sid'       : '$sid',
                            'albumid'   : albumid,
                            'auto_login_hash'   :'$uphash',
                            'output_charset': '$_G[charset]'
                        };
                        $('#file_upload').uploadify('settings','formData', formData);                    
                        $('#file_upload').uploadify('upload','*');
                    }
                    function onUploadStart(file) {}
                    function onUploadError(file, errorCode, errorMsg, errorString) {}
                    function onQueueComplete(queueData) {
                        //queueData.uploadsSuccessful
                        //queueData.uploadsErrored
                        if(picids) {
                            if(confirm('图片上传完毕，是否编辑图片名称和描述？')) {
                                jslocation("{url item/member/ac/m_picture/picids/__picids__}".replace('__picids__', picids));
                            }
                        }
                    }
                    function onUploadSuccess(file, data, response) {
                        var msgbox = $('#' + file.id).find('.data');
                        if(is_numeric(data)) {
                            picids += data + '_';
                            msgbox.html(' - 上传完毕!');
                        } else {
                            var mymsg = eval('('+data+')');
                            if(data.indexOf('ERROR:') > 1) {
                                mymsg.message = mymsg.message.replace('ERROR:','');
                            }
                            msgbox.html(' - ' + mymsg.message);
                        }
                    }
                </script>
                <style type="text/css">
                    #some_file_queue { border-radius: 3px;margin-bottom: 10px;overflow: auto;padding: 5px 10px; width: 98%; }
                    .myright_middle .select_btn { height:22px; padding:0px 8px; background:#FFFFC1; border:1px solid;
                        border-top-color:#FFF2E6; border-right-color:#FFBE7D;border-bottom-color:#FFBE7D;border-left-color:#FFF2E6; 
                        font-size:12px; color:#F95D44; font-weight:normal; -moz-border-radius:3px; }
                </style>
            <!--{elseif $_GET['op'] == 'old_multi'}-->
                <div id="upload">
                    <div id="up_1" class="up_foo">
                        <form method="post" name="myform[]" action="{url item/member/ac/$ac/in_ajax/1}" target="iframe_upload" enctype="multipart/form-data">
                            <input type="hidden" name="multi" value="yes" />
                            <input type="hidden" name="sid" value="$sid" />
                            <input type="hidden" name="albumid" value="" />
                            <input type="hidden" name="dosubmit" value="yes" />
                            <div style="margin:5px;padding:0 10px;">
                                <p>图片标题：<input type="text" name="title" class="t_input" size="35" /></p>
                                <p>图片链接：<input type="text" name="url" size="35" class="t_input" value="http://" ></p>
                                <p>选择图片：<input type="file" name="picture" size="25" onchange="pic_name(this);" ></p>
                            </div>
                        </form>
                    </div>
                </div>
                <div style="clear:both;text-align:center;padding-top:10px;">
                    <input type="hidden" id="sid" value="$sid" />
                    <input type="hidden" id="forward" value="{print get_forward()}" />
                    <button type="button" onclick="pic_upload_add();">增加上传栏</button>&nbsp;
                    <button type="button" onclick="pic_upload_start();">开始上传</button>&nbsp;
                    <button type="button" onclick="location='{url item/member/ac/$ac/sid/$sid}'">返回单个上传</button>
                </div>
                <iframe name="iframe_upload" id="iframe_upload" style="display:none;"></iframe>
                <script type="text/javascript">
                    var num = $multi_num;
                    var index = 1;
                    var errcount = 0;
                    var current = 1;
                    var currentform='';
                    $(document).ready(function() {
                        var formrail = $('#up_1').clone();
                        $(formrail).attr('id','formrail').css('display','none');
                        $(document.body).append(formrail);
                    });
                    function pic_name(obj) {
                        var addupload = true; 
                        $('#upload').find("[name='picture']").each(function() {
                            if($(this).val() == '') {
                                addupload = false;
                                return false;
                            }
                        });
                        if(addupload) pic_upload_add();
                        //自动加文件名
                        var value = obj.value;
                        var box=$(obj).parent().parent().find("[name=title]");
                        if(box.val()!='')return;
                        var filename = value.substr(value.lastIndexOf('\\')+1);
                        box.val(filename.substr(0,filename.lastIndexOf('.')));
                    }
                    function pic_upload_add() {
                        if(current >= num) { alert('批量上传不可超过'+num+'张图片，请分批上传。'); return; }
                        var foo = $('<div></div>').attr('id','up_'+current).addClass('up_foo').append($('#formrail').html());
                        $('#upload').append(foo);
                        current++;
                    }
                    function pic_upload_start() {
                        pic_upload_remove();
                        if(!pic_upload_check()) return;
                        $('#iframe_upload').load(pic_upload);
                        errcount = 0;
                        $('#upload form').each(function(i) {
                            $(this).attr('uploaded','N');
                        });
                        if(currentform = pic_upload_next()) {
                            currentform.submit();
                        }
                    }
                    function pic_upload_check() {
                        var xx = 0;
                        var albumid = $('#albumid').val();
                        if(!is_numeric(albumid)) {
                            alert('未选择上传图片的所属相册。');
                            return false;
                        }
                        $('#upload form').each(function(i) {
                            xx++;
                            var form = $(this);
                            var title = form.find("[name=title]");
                            var empty_index = 0;
                            if(title.val()=='') {
                                empty_index++;
                                title.css('background','#FF66FF');
                            } else {
                                title.css('background','#FFF');
                            }
                            var file = form.find("[name=picture]");
                            if(file.val()=='') {
                                empty_index++;
                                file.css('background','#FF66FF');
                            } else {
                                file.css('background','#FFF');
                            }
                            if(empty_index=='1') {
                                alert('图片上传栏没有填写完整。');
                                return false;
                            }
                            form.find("[name=albumid]").each(function () {
                                $(this).val(albumid);
                            });
                        });
                        if(!xx) {
                            pic_upload_add();
                            alert('没有任何图片，请先选择上传的图片。');
                            return false;
                        }
                        return true;
                    }
                    function pic_upload_remove() {
                        $('#upload form').each(function(i) {
                            if($(this).find("[name=title]").val()=='' && $(this).find("[name=picture]").val()=='') {
                                $(this).parent().remove();
                                current--;
                            }
                        });
                    }
                    function pic_upload_next() {
                        var form = null; 
                        var uploaded = true;
                        $('#upload form').each(function(i) {
                            if($(this).attr('uploaded')!='Y' && uploaded) {
                                uploaded = false;
                                form = this;
                            }
                        });
                        return form ? $(form) : false;
                    }
                    function pic_upload() {
                        currentform.attr('uploaded','Y');
                        var currentdiv = currentform.parent();
                        var iframe = document.getElementById('iframe_upload');
                        var data = $(iframe.contentWindow.document.body).html();
                        if(data.match(/\{\s+caption:".*",message:".*".*\s*\}/)) {
                            var mymsg = eval('('+data+')');
                            if(data.indexOf('ERROR:') > 1) {
                                errcount++;
                                mymsg.message = mymsg.message.replace('ERROR:','');
                                var close = $('<a></a>').attr('href','javascript:void(0);').html('<center>[关闭]</center>').click(function() {
                                    $(this).parent().remove();
                                    return false;
                                });
                                var offset = currentdiv.position();
                                var msg = $('<div></div>').append(mymsg.message).append(close)
                                    .css({position:'absolute',background:'#FFFFCC',textAlign:'center',
                                    lineHeight:'180%',zIndex:'100',top:offset.top+1,width:'380px',color:'red'});
                                currentform.before(msg);
                            } else {
                                currentdiv.html('<p style="line-height:200%;">'+currentform.find('[name=title]').val() + '<br />' + mymsg.message+'</p>')
                                .css('text-align','center');
                            }
                        } else {
                            currentdiv.html(data);
                        }
                        currentform = pic_upload_next();
                        if(currentform) {
                            currentform.submit();
                        } else if(!errcount) {
                            if(confirm('图片上传成功，是否继续上传？')) {
                                document.location.href = document.location.href;
                            } else {
                                document.location.href = Url('item/member/ac/m_picture');
                            }
                        }
                    }
                </script>
                <style type="text/css">
                    #upload { width:100%; margin-top:5px; }
                    .up_foo { float:left;width:380px;border:1px solid #eee; height:120px; }
                    .up_foo p { margin:10px 0; padding:0; }
                </style>
            <!--{else}-->
                <script type="text/javascript">
                //自动加文件名
                function pic_name(obj) {
                    var value = obj.value;
                    var box=$("[name=title]");
                    if(box.val()!='')return;
                    var filename = value.substr(value.lastIndexOf('\\')+1);
                    box.val(filename.substr(0,filename.lastIndexOf('.')));
                }
                </script>
                <form method="post" name="myform" action="{url item/member/ac/$ac/rand/$_G[random]}" enctype="multipart/form-data">
                <table width="100%" cellspacing="0" cellpadding="0" class="maintable">
                    <tr>
                        <td width="100" align="right">{$model[item_name]}名称：</td>
                        <td width="*"><a href="{url item/detail/id/$subject[sid]}" target="_blank">$subject[name]&nbsp;$subject[subname]</a></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right"><span class="font_1">*</span>所属相册：</td>
                        <td>
                            <select name="albumid" id="albumid">
                                {print form_item_alubm($sid, $albumid)}
                            </select>
                            {if $access_create_album}<button type="button" onclick="item_create_album($sid);">新建相册</button>{/if}
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right" valign="top"><span class="font_1">*</span>选择图片：</td>
                        <td><input type="file" name="picture" class="f_input" onchange="pic_name(this)"><br /><span class="font_3">最大允许上传的图片大小<span class="font_2">$_CFG[picture_upload_size]KB</span>，允许上传的图片格式 jpg、png、gif</span></td>
                    </tr>
                    <tr>
                        <td align="right"><span class="font_1">*</span>图片标题：</td>
                        <td><input type="text" name="title" size="35" class="t_input">&nbsp;<span class="font_3">&nbsp;限制<span class="font_2">30</span>个字符</span></td>
                    </tr>
                    <tr>
                        <td align="right">图片链接：</td>
                        <td><input type="text" name="url" size="45" class="t_input" value="http://">&nbsp;<span class="font_3">&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">图片说明：</td>
                        <td><input type="text" name="comments" size="45" class="t_input">&nbsp;<span class="font_3">&nbsp;限制<span class="font_2">60</span>个字符</span></td>
                    </tr>
                </table>
                <div class="text_center">
                    <input type="hidden" name="sid" value="$sid" />
                    <input type="hidden" name="forward" value="{print get_forward()}" />
                    <button type="submit" name="dosubmit" value="yes">开始上传</button>&nbsp;
                    <!--{if $MOD['multi_upload_pic']}-->
                    <button type="button" onclick="location='{url item/member/ac/$ac/op/multi/sid/$sid}'">批量上传</button>&nbsp;
                    <!--{/if}-->
                    <button type="button" onclick="history.go(-1);">返回</button>
                </div>
                </form>
            <!--{/if}-->
            </div>
        </div>
    </div>
    <div class="clear"></div>
</div>
<div class="mybottom"></div>
</div>
<!--{eval footer();}-->